#pragma once
#include <set>

namespace bs
{
	class IProgListener
	{
	public:
		virtual void OnTimeUp(int id) = 0;
	};

	class ProgTimer
	{
	public:
		ProgTimer();
		~ProgTimer();

		void AttachListener(IProgListener* listener) { this->listeners.insert(listener); }
		void DetachListener(IProgListener* listener) { this->listeners.erase(listener); }

		bool SetTime(int duration, int _id = 0);
		void SetSize(int _w, int _h) { this->w = _w; this->h = _h; }
		void SetPos(int _x, int _y) { this->x = _x; this->y = _y; }
		void SetColor(COLORREF color);

		int GetX() { return this->x; }
		int GetY() { return this->y; }
		int GetWidth() { return this->w; }
		int GetHeight() { return this->h; }

		void Start();
		void Update(int elapse);
		void Draw(HDC dc);
		void Stop();

	private:
		HBRUSH hbr;

		int x, y;
		int w, h;
		int counter;
		int target;
		int id;

		bool running;

		std::set<IProgListener*> listeners;
	};

}
